package com.haoshuang.zhouzhoubang.ui.page.study.exam

import com.haoshuang.zhouzhoubang.model.api.ApiRepo
import com.haoshuang.zhouzhoubang.model.bean.ExamQuestionBean
import com.mufeng.libs.base.BaseViewModel
import com.mufeng.libs.net.ResponseBean
import com.mufeng.libs.net.netRequest
import com.mufeng.libs.state.StateData
import com.mufeng.libs.state.StatefulMutableLiveData

class ExamViewModel : BaseViewModel() {

    /**
     * 获取考试题目
     */
    val getTrainExamQuestionData = StatefulMutableLiveData<ResponseBean<ExamQuestionBean>>()
    fun getTrainExamQuestion(articleId: Int) = netRequest {
        start { getTrainExamQuestionData.value = StateData.Loading }
        request { ApiRepo.getTrainExamQuestion(articleId) }
        success { getTrainExamQuestionData.value = StateData.Success(it) }
        error { code, msg ->
            getTrainExamQuestionData.value = StateData.Error(code, msg)
        }
    }

    /**
     * 提交考试结果
     */
    val submitExamResultData = StatefulMutableLiveData<ResponseBean<Any>>()
    fun submitExamResult(
        rate: String,
        integral: String,
        type: String,
        article_id: Int,
        ture_num: String,
        error_num: String
    ) = netRequest {
        start { submitExamResultData.value = StateData.Loading }
        request { ApiRepo.submitExamResult(rate, integral, type, article_id, ture_num, error_num) }
        success { submitExamResultData.value = StateData.Success(it) }
        error { code, msg ->
            submitExamResultData.value = StateData.Error(code, msg)
        }
    }

}